﻿using System;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using EBE.COM.Core.Interfaces;
using EBE.COM.Core.Models;

namespace EBE.COM.Infrastructure.Data
{
  public class EfCategoryRepository : EfRepositoryBase, ICategoryRepository
  {
    public DbSet<Category> Categories { get; set; }

    public IQueryable<ICategory> FindAll()
    {
      return Categories;
    }

    public IQueryable<ICategory> Find(Expression<Func<ICategory, bool>> predicate)
    {
      return Categories.Where(predicate);
    }

    public ICategory FindById(int id)
    {
      return Categories.FirstOrDefault(e => e.Id == id);
    }

    public void Add(ICategory newEntity)
    {
      Categories.Add((Category)newEntity);
      SaveChanges();
    }

    public void Remove(ICategory entity)
    {
      Categories.Remove((Category)entity);
      SaveChanges();
    }

    public void Update(ICategory entity)
    {
      throw new NotImplementedException();
    }
  }
}
